package com.jfire.orm;

import java.util.List;
import com.jfire.orm.annotation.BatchUpdate;
import com.jfire.orm.annotation.Query;
import com.jfire.orm.annotation.Update;
import com.jfire.orm.entity.User;

public interface UserDAO
{
    @Query(sql = "select username from user order by userid", paramNames = {})
    public List<String> getUsernames();
    
    @Query(sql = "select ^name from @User where ^id={userid}", paramNames = { "userid" })
    public String getUserName(int userid);
    
    @Query(sql = "select ^id,username,^age from @User where userid={id}", paramNames = { "id" })
    public User getUserByid(int id);
    
    @Query(sql = "select * from @User where ^id={id}", paramNames = { "id" })
    public List<User> getUserByidWithName(int id);
    
    @Update(sql = "insert into @User (^name,^age,password,birthday,^id) values({user.name},{user.age},{user.password},{user.birthday},{user.id})", paramNames = { "user" })
    public int insertUser(User user);
    
    @Update(sql = "delete  from @User where userid={id}", paramNames = { "id" })
    public int deleteUser(int id);
    
    @BatchUpdate(sql = "insert into user (username,age,password,birthday,userid) values({user.name},{user.age},{user.password},{user.birthday},{user.id})", paramNames = { "user" })
    public int[] insertUsers(List<User> user);
    
    @Query(sql = "select * from @User where 1=1 [$user.age] and ^age={user.age}# [$user.name] and username like %{user.name}%# [$user.id] and userid={user.id}#", paramNames = { "user" })
    public List<User> dynamicQuery(User user);
    
    @Query(sql = "select * from @User where ^id in ~{ids} and ^name = '林斌'", paramNames = { "ids" })
    public List<User> listinquestion(String ids);
    
    @Query(sql = "select * from @User where ^id in ~{ids} and ^name = '林斌'", paramNames = { "ids" })
    public List<User> listinquestion(int[] ids);
    
    @Query(sql = "select * from @User where ^id in ~{ids} and ^name = '林斌'", paramNames = { "ids" })
    public List<User> listinquestion(Integer[] ids);
    
    @Update(sql = "update @User set ^name={name} where ^id in ~{ids}", paramNames = { "name", "ids" })
    public void updatename(String name, String ids);
    
    @Query(sql = "select ^name from @User [$age > 15 && $age < 20] where ^id =1 # [ $age <=15] where ^id=3 #", paramNames = "age")
    public String name2(Integer age);
}
